package file;

import java.io.File;
import java.io.FileFilter;
import java.util.logging.Filter;

/**
 * 获取当目录中的所有文本文件.txt
 * 依然使用lambda方法，参照Test5
 */
public class Test6 {
    public static void main(String[] args) {
        /*File dir = new File(".");
        if(dir.isDirectory()){
            FileFilter filter = new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                    String name = pathname.getName();
                    boolean a = name.contains("e");
                    return a;
                }
            };
            File[] subs = dir.listFiles(filter);
            for(File sub : subs){
                System.out.println(sub.getName());
            }
        }
    }*/
        //简写accept方法，同时用lambda方法写：
        File dir = new File(".");
        if(dir.isDirectory()){
            File[] subs = dir.listFiles(pathname->pathname.getName().endsWith(".txt"));
            for(File sub:subs){
                System.out.println(sub.getName());
            }
        }
    }
}
